package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.addHolidayBean;


/**
 * Created by XXX on 2017/5/27.
 */

public class AddHolidayAdapter extends RecyclerView.Adapter<AddHolidayAdapter.MyViewHolder> implements View.OnClickListener{

    private Context context;
    private List<addHolidayBean> list;
    private OnItemClickListener monItemClickListener=null;
    //点击接口
    public static interface OnItemClickListener{
        void onClick(View view,int position);
    }

    public AddHolidayAdapter(Context context,List<addHolidayBean> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.addholidayinfo,parent,false);
        MyViewHolder holder=new MyViewHolder(view);
        view.setOnClickListener(this);

        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        addHolidayBean holidayBean=list.get(position);
        holder.select_date.setText(holidayBean.getDateStr());
        if (holidayBean.getType().equals("xiuxi")){
            holder.holidayType.setText("休息");
        }
        if (holidayBean.getType().equals("nianjia")){
            holder.holidayType.setText("年假");
        }
        if (holidayBean.getType().equals("qitajia")){
            holder.holidayType.setText("其他假");
        }
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }


    public void setOnItemClickListener(OnItemClickListener listener){
        this.monItemClickListener=listener;
    }
    @Override
    public void onClick(View v) {
        if (monItemClickListener!=null){
            monItemClickListener.onClick(v,(int)v.getTag());
        }
    }



    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView select_date;
        TextView holidayType;

        public MyViewHolder(View itemView) {
            super(itemView);
            select_date= (TextView) itemView.findViewById(R.id.select_date);
            holidayType= (TextView) itemView.findViewById(R.id.holidayType);
        }
    }
}
